package content.views.contact;
import feffects.easing.Quad;
import js.Lib;
import tools.ASprite;
import tools.BoundProvider;

/**
 * ...
 * @author PRASS
 */

class ContactItem extends ASprite 
{
	
	private var _delay 	: Int;
	private var _lbl	: ASprite;
	private var _content: ASprite;
	
	private var _ready	: Bool;
	
	public function new( jq : JQuery, pId : String) 
	{
		super(jq,pId);

		_lbl = new ASprite( new JQuery("#" + pId + " .title") );
		_lbl.setAlpha(0);
		_lbl.setHeight(40);
		
		_content = new ASprite( new JQuery("#" + pId + " .content") );
		_content.setAlpha(0);
		
		dom.css("position", "relative");
			
		setAlpha(0);
		setHeight(1);
		setWidth(1);
	}
	
	public function display( delay : Int = 0, initY : Int = 0 ) : Void
	{
		setAlpha(0);
		_lbl.setAlpha(0);
		setHeight(1);
		setWidth(1);
		setAlpha(1);
		
		_delay = delay;
		tween(1, setWidth, BoundProvider.winW - 216, 400, Quad.easeInOut, next, _delay);
	}
	
	private function next() : Void
	{
		tween(1, setHeight, 50, 400, Quad.easeInOut, null, _delay );
		_lbl.tween( 0, _lbl.setAlpha, 1, 350, Quad.easeIn, _active, _delay + 400);
	}
	
	private function _active() : Void
	{
		_lbl.dom.mouseover( function(e) { _onOver(e); } );
		_lbl.dom.mouseout( function(e) { _onOut(e); } );
		
		_ready = true;
	}
	
	/* Hide */
	public function hide( delay : Int = 0 ) : Void
	{	
		_ready = false;
		
		_lbl.tween( 1, _lbl.setAlpha, 0, 150, Quad.easeIn, null, delay);
		tween(getAlpha(), setAlpha, 0, 200, Quad.easeInOut, null, delay);
		_content.setAlpha(0);
	}
	
	private function _onOver(e) : Void
	{		
		tween(50, setHeight, 90, 300, Quad.easeInOut);
		_lbl.tween(_lbl.getHeight(), _lbl.setHeight, 80, 300, Quad.easeInOut);
		_content.tween(_content.getAlpha(), _content.setAlpha, 1, 300, Quad.easeInOut);
	}
	
	private function _onOut(e) : Void
	{
		tween(getHeight(), setHeight, 50, 300, Quad.easeInOut);
		_lbl.tween(_lbl.getHeight(), _lbl.setHeight, 40, 300, Quad.easeInOut);
		_content.tween(_content.getAlpha(), _content.setAlpha, 0, 300, Quad.easeOut);
	}
	
	public function resize() : Void
	{
		if (!_ready) return;
		tween(getWidth(), setWidth, BoundProvider.winW - 216, 400, Quad.easeOut);
	}
	
}